package com.example.study.common.base;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @author kuotian
 */

@Data
@NoArgsConstructor
@AllArgsConstructor
public class RestResponse<T> implements Serializable {
    private int code;
    private String message;
    private T data;
    public static <T> RestResponse<T> build(BaseException bizException) {
        return new RestResponse<>(bizException.getCode(), bizException.getMessage(), null);
    }

    /**
     * 静态构造器
     *
     * @param data
     *            响应数据
     * @return RestResponse
     */
    public static <T> RestResponse<T> build(T data) {
        return new RestResponse<>(CommonResponseCode.SUCCESS.getCode(), CommonResponseCode.SUCCESS.getMessage(), data);
    }
}
